package com.zhanghu.backendZray.converter;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.zhanghu.backendZray.pojo.entity.AlbumCollection;
import com.zhanghu.backendZray.pojo.request.album.AlbumCollectionRequest;
import com.zhanghu.backendZray.pojo.vo.albumCollection.AlbumCollectionVo;
import org.springframework.stereotype.Component;


/**
 * @author ZhangDong
 * @date 2024/8/19 17:46
 */
@Component
public class AlbumCollectionConverter extends Converter<AlbumCollectionRequest, AlbumCollection, AlbumCollectionVo> {
    protected AlbumCollectionConverter() {
        super(AlbumCollectionConverter::albumRequest2Entity, AlbumCollectionConverter::albumEntity2Vo);
    }

    private static AlbumCollection albumRequest2Entity(AlbumCollectionRequest request) {
        AlbumCollection albumCollection = new AlbumCollection();
        albumCollection.setId(request.getId());
        albumCollection.setCollectionName(request.getCollectionName());
        albumCollection.setUserId(request.getUserId());
        return albumCollection;
    }

    private static AlbumCollectionVo albumEntity2Vo(AlbumCollection albumCollection) {
        AlbumCollectionVo albumCollectionVo = new AlbumCollectionVo();
        albumCollectionVo.setId(albumCollection.getId());
        albumCollectionVo.setCollectionName(albumCollection.getCollectionName());
        albumCollectionVo.setCoverFileId(albumCollection.getCoverFileId());
        String fileIdListStr = albumCollection.getFileIdList();
        if (StrUtil.isNotEmpty(fileIdListStr)) {
            albumCollectionVo.setFileIdList(JSON.parseArray(fileIdListStr, Integer.class));
        }
        return albumCollectionVo;
    }
}
